Respectful Type Converters For Mutable Types

نویسندگان

  • Jeannette M. Wing
  • John Ockerbloom
چکیده

In converting an object of one type to another, we expect some of the original object's behavior to remain the same, and some to change. How can we state the relationship between the original object and converted object to characterize what information is preserved and what is lost after the conversion takes place? We answer this question by introducing the new relation, respects, and say that a type converter function K : A! B respects a type T . We formally de ne respects in terms of the Liskov and Wing behavioral notion of subtyping; types A and B are subtypes of T . In previous work [11] we de ned respects for immutable types A, B, and T; in this paper we extend our notion to handle conversions between mutable types. This extension is non-trivial since we need to consider an object's behavior as it varies over time. We present in detail two examples to illustrate our ideas: one for converting between PNG images and GIF images and another for converting between di erent kinds of bounded event queues. We also discuss in less detail other real-world applications, namely those inspired by our Typed Object Model (TOM) conversion service built at Carnegie Mellon and by the infamous Year 2000 (Y2K) problem. 1 Motivation The tremendous growth of the Internet and the World Wide Web gives millions of people access to vast quantities of data. While users may be able to retrieve data easily, they may not be able to interpret or display retrieved data intelligibly. For example, when retrieving a Microsoft Word document, without a Microsoft Word program, the user will be unable to read, edit, display, or print it. In general, the type of the retrieved data may be unknown to the retrieving site. Users and programs cope with this problem by converting data from one type to another, e.g., from the unknown type to one known by the local user or program. Thus, to view the Word document, we could convert it to ASCII text or HTML, and then view it through our favorite text editor or browser. A picture in an unfamiliar Windows bitmap type could be converted into a more familiar GIF image type. A mail message with incomprehensible MIME attachments could be converted from an unreadable MIME-encoded type to a text, image, or audio type that the recipient could examine directly. In general, we apply type converters on (data) objects, transforming an object of one type to an object of a di erent type. 1.1 What Information Do Type Converters Preserve? In converting objects of one type to another we expect there to be some relationship between the original object and the converted one. In what way are they similar? The reason to apply a converter in the rst place is that we expect some things about the original object to change in a way that we are willing to forgo, but we also expect some things to stay the same. For example, suppose we convert a LATEX le to an HTML le. We may care to ensure that the raw textual contents of the original LATEX document are preserved, but not the formatting commands since they do not contribute to the meaning of the document itself; here the preserved information is the underlying semantics of the text contained in the document. Alternatively, if we convert a LATEX le to a table-of-contents document, we may care to ensure that the number, order, and titles of chapters and sections in the original document are preserved, but not the bulk of the text; here the preserved information is primarily the document's structure. The question we address in this paper is \How can we characterize what information is preserved by a type converter?" Our answer is given in terms of the behavior of some type T . Informally, we say a converter K : A ! B respects type T if the original object of type A and the converted object of type B have the same behavior when both objects are viewed as a type T object. That is, from T 's viewpoint, the A and B objects look the same. If the converter respects a type, then it preserves that type's observable behavior. This paper formalizes this novel notion of respectful type converters. Our particular formalization of respects exploits the subtype relationship that holds among types of objects. The Liskov and Wing notion of behavioral subtyping [8] conveniently characterizes semantic di erences between types. If S is a subtype of T , users of T objects cannot perceive when objects of type S are substituted for T objects. Intuitively, if K respects type T , an ancestor of both A and B in the subtype hierarchy, then T captures the behavioral information preserved by K. In our previous work, \Respectful Type Converters" [11] we presented a de nition of respects for conversions between immutable types only. (It was correspondingly based on a simpli ed version of Liskov and Wing's de nition of subtype.) In this paper, we present an enhanced version of our respects relation that captures important properties of conversions between mutable types. Speci cally, for mutable types we say that a conversion respects a certain type T if an object with the converted value cannot be distinguished (using T 's interface speci cation) from an object with the original value either at the time of conversion, or by analyzing any future computation on the object. That is, the future subhistory of the new object will not be inconsistent with the expectations raised by the past subhistory of the original object, given the constraints of type T . This paper spells out how to determine whether a given ancestor T in a type hierarchy is respected by a converter K : A ! B (Figure 1). In general, A and B need not be subtypes of each other; in practice, they are often siblings or cousins in a given type hierarchy. Also, in general, T is not necessarily the least common ancestor of A and B. Here is an example of why T is not just any ancestor of A and B. Figure 2 depicts a type family for images. Suppose that the PNG image and GIF image types are both subtypes of a pixel map type that speci es the colors of the pixels in a rectangular region. GIF images are limited to 256 distinct colors; PNG 1

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Respectful Type Converters

In converting an object of one type to another, we expect some of the original object's behavior to remain the same, and some to change. How can we state the relationship between the original object and converted object to characterize what information is preserved and what is lost after the conversion takes place? We answer this question by introducing the new relation, respects, and say that ...

متن کامل

Respectful Type Converters 1.1 What Information Do Type Converters Preserve?

In converting an object of one type to another, we expect some of the original object's behavior to remain the same, and some to change. How can we state the relationship between the original object and converted object to characterize what information is preserved and what is lost after the conversion takes place? We answer this question by introducing the new relation, respects, and say that ...

متن کامل

An Indexed Model of Impredicative Polymorphism and Mutable References

We present a semantic model of the polymorphic lambda calculus augmented with a higher-order store, allowing the storage of values of any type, including impredicative quantified types, mutable references, recursive types, and functions. Our model provides the first denotational semantics for a type system with updatable references to values of impredicative quantified types. The central idea b...

متن کامل

Type soundness for Core Mezzo

Mezzo is a programming language in the tradition of ML. It offers algebraic data types, first-class functions, and a system of duplicable or affine permissions that controls aliasing and access to mutable memory. We present a formal definition of Core Mezzo, an explicitly-typed calculus that underlies Mezzo, and establish the soundness of its type and permission system. Our definitions and proo...

متن کامل

Semantic subtyping between coinductive mutable record types with unions and intersections

Semantic subtyping between coinductive record types supports accurate type analysis of object-oriented languages, by introducing Boolean type constructors and modeling cyclic objects. In previous work, a sound and complete algorithm for semantic subtyping has been proposed, but only for coinductive immutable record types with unions. In this work we address the issue of extending the previous r...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1999